import asyncio
import requests
import time
import aiohttp

url = "http://127.0.0.1:8000/get-report"

async def get_report(i: int):
    print(f"Starting request {i}")
    #resp = requests.get(url)
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as resp:
            resp.raise_for_status()
            return await resp.json()


async def main():
    # 运行5个并发请求，并获取数据返回
    # for i in range(5):
    #     tasks.append(asyncio.create_task(get_report()))
    tasks = [asyncio.create_task(get_report(i)) for i in range(5)]
    results  = await asyncio.gather(*tasks)
    for result in results:
        print(result)

if __name__ == "__main__":
    # 计算执行时间
    start_time = time.time()
    print("Start:"+str(start_time))
    asyncio.run(main())
    end_time = time.time()
    print("End:"+str(end_time))
    print(f"Total time taken: {end_time - start_time} seconds")

